<?php
//Imagick实现的验证码
//by surfchen
//license BSD

function makeColor(){
    $c = array();
    $max=255;
    for ($i=0;$i<3;$i++) {
        $c[$i]=rand(0,$max);
        $max-=$c[$i];
    }
    shuffle($c);
    return 'rgb('.$c[0].','.$c[1].','.$c[2].')';
}

$color = makeColor();
$swirl = rand(-25,-15);
$pointsize  = rand(18, 20);
$image_width=70;
$image_height=25;
$position_x=0;
$position_y=20;
$text = '';
for ($i = 0; $i < 6; $i++) {
    $text .= chr(rand(97,122));
}


header('Content-type: image/png');
$image = new Imagick();
$image->newPseudoImage($image_width,$image_height,'xc:white');
$image->setImageFormat('png');

$ipix=new ImagickPixel($color);

$idraw=new ImagickDraw;
$idraw->setFillAlpha(1.0);
//$idraw->setFont('arial.ttf');
$idraw->setFontSize($pointsize);
$idraw->setFillColor($ipix);
$idraw->annotation($position_x,$position_y,$text);

$image->drawImage($idraw);
$image->swirlImage($swirl);
echo $image;
